// Copyright (c) 2007 Alistair Jones
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.codegen;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

import java.util.HashSet;

public class ElementTest {

    @Test
    public void shouldGenerateInterfaceThatExtendsGenericContainsInterface() {
        Element element = new Element("air");

        GeneratedInterface elementInterface = element.createElementInterface();

        assertTrue(elementInterface.baseInterfaces.contains("Contains<Air, AirContent>"));
    }
    
    @Test
    public void shouldGenerateMethodBodiesThatInstantiateChildElements() {
        Element element = new Element("air");
        HashSet<String> contentElements = new HashSet<String>();
        contentElements.add("earth");
        element.addContentElementTypes(contentElements);
        GeneratedClass generatedClass = element.createElementImplementation();

        Constructor constructor = (Constructor) generatedClass.getMembers().get(0);
        assertEquals("super(\"air\", attributes);", constructor.getMethodBody());

        ConcreteMethod method = (ConcreteMethod) generatedClass.getMembers().get(1);
        assertEquals("earth", method.getMethodName());
        assertEquals("Earth", method.getReturnType());
        assertEquals("return newChild(new EarthElement(attributes));", method.getMethodBody());

        ConcreteMethod textMethod = (ConcreteMethod) generatedClass.getMembers().get(2);
        assertEquals("text", textMethod.getMethodName());
        assertEquals("Text", textMethod.getReturnType());
        assertEquals("return newChild(new Text(content));", textMethod.getMethodBody());
    }


}